package com.zjx.Service.impl;

import com.zjx.Service.StudentService;
import com.zjx.Service.StudentService2;
import com.zjx.entity.Student;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.sql.Types;

/**
 * @author zhaojiaxu
 * @date 2021/08/25 16:07
 **/
public class StudentServiceImpl2 implements StudentService2 {

	private JdbcTemplate jdbcTemplate;

	public void setDateSource(DataSource dateSource) {
		this.jdbcTemplate = new JdbcTemplate(dateSource);
	}

	@Override
	public void delete(Student student) throws Exception {
                  System.out.println("B后删除student");
				 jdbcTemplate.update("delete from student where id = ?",
						 new Object[]{student.getId()}, new int[]{
								 Types.INTEGER});
				 //事务测试，加上这句代码则数据不会保存到数据库中
				 //throw new RuntimeException("测试失败");

				 //事务测试，如果抛出Exception会不会回滚呢 结果是不会产生回滚
				 throw new RuntimeException("测试失败");

	}
}


